home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
smaltalk
/
manchest.lha
/
MANCHESTER
/
manchester
/
2.2
/
continuations.st
< prev
next >
Wrap
Text File
|
1993-07-24
|
2KB
|
103 lines
" NAME continuations
AUTHOR ikp@cs.man.ac.uk
FUNCTION continuations, as in Scheme
ST-VERSIONS 2.2
PREREQUISITES
CONFLICTS
DISTRIBUTION world
VERSION 1.1
DATE 22 Jan 1989
SUMMARY continuations
provides a continuation mechanism (a la Scheme).
Sending a block the message ""callCC"" activates the block, passing
the current continuation as the argument. This continuation can be
triggered by sending it a ""value: anObect"" message; control will
jump back to the point at which the continuation was created, with
anObject as the result. Once created, a continuation can be fired
any number of times. To fire a continuation that is never needed
again, you can use ""oneShotValue: anObject"" which is a little more
efficient. The trivial case ""[:x|x] callCC"" takes 40mS on our
3/180. See R. K. Dybvig, ""The Scheme Programming Language"",
section 4.6. (2.2). IKP
"!
'From Smalltalk-80, Version 2.2 of July 4, 1987 on 8 November 1988 at 6:40:11 am'!
!ContextPart methodsFor: 'accessing'!
copyStack
sender isNil ifTrue:[^self copy] ifFalse: [^(self copy) sender: self sender copyStack]! !
'From Smalltalk-80, Version 2.2 of July 4, 1987 on 8 November 1988 at 6:40:32 am'!
!ContextPart methodsFor: 'accessing'!
sender: s
sender _ s! !
'From Smalltalk-80, Version 2.2 of July 4, 1987 on 8 November 1988 at 6:57:37 am'!
Object subclass: #Continuation
instanceVariableNames: 'stack '
classVariableNames: ''
poolDictionaries: ''
category: 'Kernel-Methods'!
!Continuation methodsFor: 'private'!
stack
^stack!
stack: s
stack _ s! !
!Continuation methodsFor: 'invocation'!
oneShotValue
thisContext sender: stack.
^nil!
oneShotValue: v
"escape to the original continuation with v as the result, discarding the stack on the way"
thisContext sender: stack.
^v!
value
thisContext sender: stack copyStack.
^nil!
value: v
"return to the original continuation, copying the stack to allow another activation"
thisContext sender: stack copyStack.
^v! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
Continuation class
instanceVariableNames: ''!
!Continuation class methodsFor: 'instance creation'!
fromContext: aStack
^super new stack: aStack copyStack! !
'From Smalltalk-80, Version 2.2 of July 4, 1987 on 8 November 1988 at 6:40:54 am'!
!BlockContext methodsFor: 'continuations'!
callCC
^self value: (Continuation fromContext: thisContext sender)! !